
const defaultState = {
    inputPlaceholder: "Write Something to do",
    inputValue: "",
    list: [
        { content: "CSS学习,布局等知识", done: 1 },
        { content: "三大框架的学习", done: 1 },
        { content: "node 写后端的接口", done: 1 },
    ]
}
// eslint-disable-next-line
export default (state = defaultState, action) => {
    // Reducer 里只能接受state,不能改变state
    if (action.type === "inputChange") {
        let newState = JSON.parse(JSON.stringify(state))
        newState.inputValue = action.value
        return newState
    }
    // 添加列表项
    if (action.type === 'add') {
        let newState = JSON.parse(JSON.stringify(state))
        newState.list.push(newState.inputValue)
        console.log(newState);
        newState.inputValue = ""
        return newState
    }
    //删除列表项
    if (action.type === "deleteItem") {

        let newState = JSON.parse(JSON.stringify(state))
        newState.list.splice(action.index, 1)
        return newState
    }
    return state
}